//Copyright © 2012 Ryan Larson, Ben Glasser
//[This program is licensed under the "GPL v3.0 License"]
// Please see the file COPYING in the source
//distribution of this software for license terms.
package org.app_chat.test;

import org.apache.activemq.broker.BrokerService;
import org.app_chat.api.Broker;

/**
 * Copyright (c) 2012 Ryan Larson, Ben Glasser
 * Created by Ryan of app-chat.org
 * on: 8/8/12 at 10:32 AM
 */

/**
 * An implementation of the {@link Broker} that embeds an ActiveMQ
 * Broker in the JavaVM
 */
public class BrokerImpl implements Broker {

    private final String brokerUrl = "vm://testChatBroker";
    private final BrokerService broker;

    /**
     * Public constructor
     *
     * @throws Exception this is for unit testing, java unit testing frameworks
     *                   know what to do with Exceptions
     */

    public BrokerImpl() throws Exception {
        broker = new BrokerService();

        broker.setPersistent(false);
        broker.setUseJmx(false);
        broker.addConnector(brokerUrl);
    }

    /**
     * Start up the broker
     *
     * @throws Exception
     */

    @Override
    public void start() throws Exception {
        broker.start();
    }

    /**
     * Shut down the broker
     *
     * @throws Exception
     */

    @Override
    public void stop() throws Exception {
        broker.stop();
    }
}
